import uploadImg from '@/libs/upload-img'
let _self;
export const index =  {
	props: {
		images:{type:Array,default:[]}
	},
	data() {
		return {
			fileList: []
		}
	},
	
	
	watch:{
		fileList(val){
			this.$emit('update:images', val);
		},
		
		images(val) {
			this.fileList = val;
		},
		
	},
	created() {
		_self = this;
		/*this.$nextTick(() => {
		    this.initData();
		})*/
	},
	
	methods: {
		initData(){
			//this.showAgree=true;				
		},
		
		deletePic(event) {
			this["fileList"].splice(event.index, 1);
		},
		
		// 新增图片
		async afterRead(event) {
			// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
			let lists = [].concat(event.file)
			let fileListLen = this[`fileList`].length
			lists.map((item) => {
				this[`fileList`].push({
					...item,
					status: 'uploading',
					message: '上传中'
				})
			})
			for (let i = 0; i < lists.length; i++) {
				let result = await uploadImg({"url":lists[i].url});
				let item = this[`fileList`][fileListLen]
				this[`fileList`].splice(fileListLen, 1, Object.assign(item, {
					status: 'success',
					message: '',
					url: process.env.HOST+result.path
				}))
				fileListLen++
			}
			
		}
		

	}
}